package com.example.sixtrainingdemo.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.sixtrainingdemo.R;
import com.example.sixtrainingdemo.contract.MainContract;
import com.example.sixtrainingdemo.entity.Goods;
import com.example.sixtrainingdemo.entity.Shop;

import java.util.List;

public class ShopAdapter extends RecyclerView.Adapter<ShopAdapter.ViewHolder> {

   private List<Shop> mList;

   public ShopAdapter(List<Shop> mGoodsList){
      mList = mGoodsList;
   }

   public void updateData(List<Shop> list) {
      mList.clear();
      mList = list;
      notifyDataSetChanged();
   }

   @NonNull
   @Override
   public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
      View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.shop_item, null);
      ViewHolder viewHolder = new ViewHolder(view);
      return viewHolder;
   }


   public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
      Shop shop = mList.get(position);
      holder.textView1.setText(shop.getName());
      holder.textView2.setText("$ " + shop.getPrice() + "/" + shop.getUnit());

   }

   @Override
   public int getItemCount() {
      return mList.size();
   }

   public class ViewHolder extends RecyclerView.ViewHolder {
      ImageView photo;
      TextView textView1;
      TextView textView2;

      public ViewHolder(@NonNull View itemView) {
         super(itemView);
         photo = itemView.findViewById(R.id.goods_photo);
         textView1 = itemView.findViewById(R.id.shop_name);
         textView2 = itemView.findViewById(R.id.shop_price);

      }
   }
}
